/**
 * --------------------------------------
 * FileName: dual_list.h
 * Content: 
 *      数据结构第3周第一次作业前置内容
 *      一个简单的双向链表
 * 
 * Auther:  杨则瑞
 * Encode:  utf-8 | CRLF
 * --------------------------------------
 */


#ifndef _dual_list
#define _dual_list

#include<stdint.h>
#include<malloc.h>
#include<memory.h>


#define ns(lable) duList_##lable

typedef enum ns(error_t)
{
    ns(OK),
    ns(INSUFFICIENT_MEMORORY),
    ns(INDEX_OUT_OF_BOUND),

} ns(error_t);


typedef struct ns(node_t)  
{
    struct ns(node_t) *next;
    struct ns(node_t) *prev;
    int data[0];

} ns(node_t);


typedef struct ns(t)
{
    struct ns(node_t) *_header;
    int _elem_size;
    ns(error_t)* _error_handler;

} ns(t);



// Memory
int ns(init)   (ns(t) * self, size_t elem_size, ns(error_t)* error_handler);
int ns(uninit) (ns(t) * self);

// Modification
int ns(insert) (ns(t) * self, size_t pos,const void * element);
int ns(insert_reverse) (ns(t) * self, size_t pos, const void * element);
int ns(erase)  (ns(t) * self, size_t pos);
int ns(erase_reverse)  (ns(t) * self, size_t pos);
int ns(clear)  (ns(t) * self);

// Utility
int    ns(is_empty) (const ns(t) * self);
size_t ns(length)   (const ns(t) * self);
int    ns(get)      (const ns(t) * self, size_t pos, void * val_dest);
int    ns(get_reverse) (const ns(t) * self, size_t pos, void * val_dest);

#undef ns 


#endif